import 'package:flutter/material.dart';
import 'package:jieqifang/global.dart';
import 'package:jieqifang/iconfont.dart';
import 'package:jieqifang/pages/index.dart';
import 'package:jieqifang/pages/intro.dart';
import 'package:titled_navigation_bar/titled_navigation_bar.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '节气坊',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _currentIndex = 0;
  PageController _pageController;

  @override
  void initState() {
    super.initState();
    _pageController = PageController();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SizedBox.expand(
        child: PageView(
          controller: _pageController,
          onPageChanged: (index) {
            setState(() => _currentIndex = index);
          },
          children: <Widget>[
            IndexPage(),
            IntroPage(),
          ],
        ),
      ),
      bottomNavigationBar: TitledBottomNavigationBar(
        currentIndex: _currentIndex,
        reverse: true,
        enableShadow: false,
        activeColor: Global.primaryColor,
        onTap: (index) {
          setState(() => _currentIndex = index);
          _pageController.jumpToPage(index);
        },
        items: [
          TitledNavigationBarItem(
            title: Text(
              '二十四节气',
              style: TextStyle(
                color: Global.primaryColor,
                fontFamily: 'QiuHongKai',
                fontSize: 20,
                fontWeight: FontWeight.w600,
              ),
            ),
            icon: IconFont.jieqi,
          ),
          TitledNavigationBarItem(
            title: Text(
              '介绍',
              style: TextStyle(
                color: Global.primaryColor,
                fontFamily: 'QiuHongKai',
                fontSize: 20,
                fontWeight: FontWeight.w600,
              ),
            ),
            icon: IconFont.jieshao,
          ),
        ],
      ),
    );
  }
}
